﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Net.Mail;

namespace SyncUserAccount
{
    public class EmailHelper
    {
        public static void SendMail(Email email)
        {
            SmtpClient client = new SmtpClient(email.Host);
            MailMessage message = new MailMessage();
 
            message.From = new MailAddress(email.From, email.DisplayName);
            foreach (var toAdr in email.To)
            {
                message.To.Add(new MailAddress(toAdr));
            }
            foreach (var ccAdr in email.CC)
            {
                message.CC.Add(new MailAddress(ccAdr));
            }
            message.Subject = email.Subject;
            message.SubjectEncoding = System.Text.Encoding.UTF8;
            message.Body = email.Body;
            message.BodyEncoding = System.Text.Encoding.UTF8;
            message.Priority = System.Net.Mail.MailPriority.High;
            client.EnableSsl = false;
            foreach (var attachment in email.Attachment)
            {
                message.Attachments.Add(new Attachment(attachment));
            }

            try
            {
                client.Send(message);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                message.Dispose();
            }
        }

    }
}
